package com.tjnu.losca.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjnu.losca.pojo.Admin;
import com.tjnu.losca.pojo.User;
import com.tjnu.losca.service.IAdminService;
import com.tjnu.losca.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author Losca
 * @date 2022/2/13 23:33
 */
@Service
public class ILoginServiceImpl implements ILoginService {
    @Autowired
    IAdminService adminService;
    @Override
    public User getUserByUserName(String username) throws IOException {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        Admin userinfo = adminService.getOne(wrapper);
        User user = new User();
        user.setId(userinfo.getId());
        user.setUsername(userinfo.getUsername());
        user.setPwd(userinfo.getPwd());
        return user;
    }

    @Override
    public boolean updatePwdByUsername(String username, String pwd) throws IOException {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        Admin userinfo = new Admin();
        userinfo.setPwd(pwd);
        return adminService.update(userinfo, wrapper);
    }
}
